<template>
  <div>
    <x-header :left-options="{ showBack: false }">
      <header-title title="Jssdk Test" />
    </x-header>

    <div class="list-box">
      <div class="tip-line">
        <group>
          <cell title="点击测试" @click.native="openLink"/>
        </group>
        <div>
          <p id="position">获取的位置：</p>
          <p>{{ jssdkObj.position }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Group, Cell, XHeader } from 'vux';
import HeaderTitle from '@/components/common/HeaderTitle';

export default {
  name: 'JssdkTest',
  components: {
    Cell,
    Group,
    XHeader,
    HeaderTitle,
  },
  data() {
    return {
      jssdkObj: {
        position: null,
      },
    };
  },
  methods: {
    showDialog(msg) {
      this.$vux.alert.show({
        title: '提示',
        content: msg,
      });
    },
    openLink() {
      this.showNavigationBar(true);
      this.getGroupMembers();
      this.showTabBar(true);
      this.downloadFile();
      this.openFileURL();
      this.openExternalUrl();
      this.getUserInfo();
      this.getGroupsInfo();
      this.getContacts();
      this.getLocalPhotos();
      this.getLocalFiles1();
      this.getLocalPhotos1();
      this.getClientInfo();
      this.getPosition();
      this.getLocalFiles();
      this.takePhoto();
      this.closeView();
    },
    showNavigationBar(show) {
      this.$vrv.jssdk.showNavigationBar({
        show,
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },

    getGroupMembers() {
      this.$vrv.jssdk.getGroupMembers({
        groupID: 4336932476,
        page: 0,
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    showTabBar(show) {
      this.$vrv.jssdk.showTabBar({
        show,
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    downloadFile() {
      this.$vrv.jssdk.downloadFile({
        type: 1, // 1、图片 2、 文件
        url: 'http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg',
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    openFileURL() {
      this.$vrv.jssdk.openFileURL({
        // 1个文件链接
        url: 'http://dang.qdvrv.com:8088/PartyBuilding/common/img/denlu/df.png',
        name: '需要界面上显示的文件名',
        success: (res) => {
          // 失败返回 空
          // 成功 返回文件本地路径并打开
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    openExternalUrl() {
      this.$vrv.jssdk.openExternalUrl({
        // 需要加载的链接
        url: 'https://stock.linkdood.cn',
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    takePhoto() {
      this.$vrv.jssdk.takePhoto({
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    closeView() {
      this.$vrv.jssdk.closeView({
        appSign: '多人视频', // app 标识， pc 需要
      });
    },
    getUserInfo() {
      this.$vrv.jssdk.getAccountInfo({
        isEntUser: false, // 是否是企业用户 true 企业用户 false 普通用户
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    getClientInfo() {
      this.$vrv.jssdk.getClientInfo({
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },
    getPosition() {
      this.$vrv.jssdk.getPosition({
        success: (res) => {
          this.jssdkObj.position = res;
        },
      });
    },

    getLocalFiles() {
      this.$vrv.jssdk.getLocalFiles({
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },

    getGroupsInfo() {
      this.$vrv.jssdk.getGroupList({
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },

    getContacts() {
      this.$vrv.jssdk.getContactList({
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },

    getLocalPhotos() {
      this.$vrv.jssdk.getLocalPhotos({
        success: (res) => {
          try {
            this.showDialog(JSON.stringify(res));
          } catch (e) {
            this.showDialog(e.message);
          }
        },
      });
    },

    getLocalFiles1() {
      this.$vrv.jssdk.getLocalFiles({
        size: 1,
        success: (res) => {
          this.showDialog(JSON.stringify(res));
        },
      });
    },

    getLocalPhotos1() {
      this.$vrv.jssdk.getLocalPhotos({
        size: 1,
        success: (res) => {
          this.showDialog(JSON.stringify(res));
          this.showDialog(res.mPhotoPath[0]);
        },
      });
    },
  },
};
</script>

<style scoped>
.list-box {
  padding: 47px 0 10px 0;
}
.tip-line {
  text-align: left;
}
</style>
